package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.QueryAllFunctionNewRes;

/**
 * Copyright (c)2021/5/24
 * author: hxh
 * created on: 2021/5/24 10:30
 * description:关怀模式适配器
 */

public class CareModeAdapter extends RecyclerView.Adapter<CareModeAdapter.CareViewHolder> {

    private Context context;
    private ArrayList<QueryAllFunctionNewRes.ClassListBean.FunctionListBean> list;
    private CareOnclick onclick;

    public CareModeAdapter(Context context, ArrayList<QueryAllFunctionNewRes.ClassListBean.FunctionListBean> list, CareOnclick onclick) {
        this.context = context;
        this.list = list;
        this.onclick = onclick;
    }

    @NonNull
    @Override
    public CareViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new CareViewHolder(LayoutInflater.from(context).inflate(R.layout.care_mode_item, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull CareViewHolder holder, int position) {

        Glide.with(context).load(list.get(position).getIcon_url()).into(holder.imageView);
        holder.textView.setText(list.get(position).getFunction_name());
        holder.itemView.setOnClickListener(v -> onclick.clickit(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class CareViewHolder extends RecyclerView.ViewHolder{
        private TextView textView;
        private ImageView imageView;


        public CareViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.caremode_img);
            textView=itemView.findViewById(R.id.caremode_text);
        }
    }


    public interface CareOnclick{
        void clickit(int position);
    }
}
